package com.zky.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;


import com.zky.DAO.impl.UsersDaoImp;

import com.zky.common.Pagination;
import com.zky.entity.Users;

public class UsersAction extends UsersDaoImp {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public List<Users> list;
	public Pagination pagination;
	public int pageNo = 1;
	public int pageSize = 6;
	public int showCount = 6;
	public Users users;
	public Users getUsers() {
		return users;
	}
	public void setUsers(Users users) {
		this.users = users;
	}
	public List<Users> getList() {
		return list;
	}
	public void setList(List<Users> list) {
		this.list = list;
	}
	public Pagination getPagination() {
		return pagination;
	}
	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getShowCount() {
		return showCount;
	}
	public void setShowCount(int showCount) {
		this.showCount = showCount;
	}

	public String findAllUsers() {
		try {
			List<Users> all = this.findAll();
			pagination = new Pagination(pageNo, pageSize, all.size(),
					showCount, "BackBiz.action", "pagenum");
			list = pagination.getPageDate(all);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "false";
		}

	}

	public String edit() {
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			int id = Integer.parseInt(request.getParameter("id"));
			users = this.findById(id);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "false";
		}

	}

	public String update() {
		try {
			this.update(users);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "false";
		}

	}

	public String del() {
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			int id = Integer.parseInt(request.getParameter("id"));
			this.delete(id);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "false";
		}

	}

	public String add() {
		try {
			this.save(users);
			return "success";
		} catch (Exception e) {
			e.printStackTrace();
			return "false";
		}

	}
	
	/*public  List<Users> findAllUsers1(){
		  try{
		    list =this.findAll();
		          return list;
		     }
		  catch(Exception e)
		  {
		        e.printStackTrace();
			    return list;
			   }
		  
			}*/
	
	
}